<h2>DESCRIPTION</h2>

<em>r.stats</em> calculates the area present in each of the categories
or floating-point intervals of user-selected <b>input</b> raster map. Area
statistics are given in units of square meters and/or cell
counts. This analysis uses the current geographic region
(<em><a href="g.region.html">g.region</a></em>) and mask settings
(<em><a href="r.mask.html">r.mask</a></em>). The output statistics can
be saved to a <b>output</b> file.

<p>
Area statistics is printed in square meters for each category
when <b>-a</b> is given. Similarly if <b>-c</b> flag is chosen, areas
will be stated also in number of cells.

<h2>NOTES</h2>

If a single raster map is specified, a list of categories will be printed.
The <b>-x</b> flag will print x and y (column and row) starting with 1
(both first row and first column are indexed with 1). If multiple raster maps
are specified, a cross-tabulation table for each combination of categories in
the raster maps will be printed.

<p>
For example, if one raster map was specified, the output would look like:
<div class="code"><pre>
1 1350000.00
2 4940000.00
3 8870000.00
</pre></div>

If three raster maps were specified, the output would look like:
<div class="code"><pre>
0 0 0 8027500.00
0 1 0 1152500.00
1 0 0 164227500.00
1 0 1 2177500.00
1 1 0 140092500.00
1 1 1 3355000.00
2 0 0 31277500.00
2 0 1 2490000.00
2 1 0 24207500.00
2 1 1 1752500.00
3 0 0 17140000.00
3 1 0 11270000.00
3 1 1 2500.00
</pre></div>

Within each grouping, the first field represents the category value of
first raster map, the second represents the category values associated
with second raster map, the third represents category values for third
raster map, and the last field gives the area in square meters for the
particular combination of these three raster maps' categories. For
example, above, combination 3,1,1 covered 2500 square meters. Fields
are separated by the <b>separator</b> option.

<!-- do not use bash commands in the manual
<p>If a nicely formatted output is desired, pipe the output into a command
which can create columnar output.  For example, the command:

<p>    <b>r.stats input=</b>a,b,c | pr -3 | cat -s

<p>will create a three-column output 
<div class="code"><pre>
1:4:4:10000.00       2:1:5:290000.00      2:4:5:2090000.00
1:4:5:1340000.00     2:2:5:350000.00      3:1:2:450000.00
2:1:1:1090000.00     2:4:1:700000.00      3:1:3:5280000.00
2:1:3:410000.00      2:4:3:10000.00       3:1:5:3140000.00
</pre></div>
-->

The output from <em>r.stats</em> is sorted by category or category
intervals (for floating-point raster maps).

<p>
Note that the user has only the option of printing out cell statistics
in terms of cell counts and/or area totals. Users wishing to use
different units than are available here should
use <em><a href="r.report.html">r.report</a></em>.

<h2>EXAMPLES</h2>

<h3>Report area for each category</h3>

Report area for each category in the single raster map:

<div class="code"><pre>
g.region raster=geology_30m
r.stats -a in=geology_30m nv=no-data sep=tab

217     71960000.000000
262     19760000.000000
270     67760000.000000
405     25120000.000000
583     2520000.000000
720     480000.000000
766     840000.000000
862     6560000.000000
910     4360000.000000
921     1200000.000000
946     360000.000000
948     80000.000000
no-data 33375200000.000004
</pre></div>

<h3>Report sorted number of cells for each category</h3>

Report sorted number of cells for each category in the single raster
map (suppress NULL data):

<div class="code"><pre>
g.region raster=geology_30m
r.stats -cn input=geology_30m sort=desc

217 1799
270 1694
405 628
262 494
862 164
910 109
583 63
921 30
766 21
720 12
946 9
948 2
</pre></div>

<h3>Report area, number of cells, and percents in multiple raster maps</h3>

Report area, number of cells, and percents (separated by tabs) for
each category in multiple raster maps (suppress NULL data):

<div class="code"><pre>
g.region raster=towns
r.stats -nacp input=towns,urban separator=tab

1       55      23840000.000000 596     11.89%
2       55      13680000.000000 342     6.82%
3       55      1360000.000000  34      0.68%
4       55      16040000.000000 401     8.00%
5       55      98240000.000000 2456    48.98%
6       55      19760000.000000 494     9.85%
</pre></div>

<h3>Report sorted area intervals of floating-point raster map</h3>

Report sorted area for each interval of floating-point input raster
map. Number of intervals are given by <b>nsteps</b> option.

<div class="code"><pre>
g.region raster=elevation
r.stats -an input=elevation nsteps=10 sort=desc separator=tab

95.879221-105.954329    36440000.000000
85.804114-95.879221     30800000.000000
105.954329-116.029436   30080000.000000
116.029436-126.104543   27960000.000000
126.104543-136.17965    26440000.000000
136.17965-146.254757    20880000.000000
75.729007-85.804114     15880000.000000
65.6539-75.729007       6040000.000000
146.254757-156.329865   5720000.000000
55.578793-65.6539       760000.000000
</pre></div>

<h3>Report raster cell counts in multiple raster maps</h3>

Report raster cell counts of landuse and geological categories within
zipcode areas:

<div class="code"><pre>
g.region raster=zipcodes
# landuse/landcover and zipcodes
r.stats -c input=landclass96,zipcodes separator=comma 

# landuse/landcover, geology and zipcodes with category labels
r.stats -c input=landclass96,zipcodes,geology_30m separator=comma -l
</pre></div>

<h2>SEE ALSO</h2>

<em>
<a href="g.region.html">g.region</a>,
<a href="r.report.html">r.report</a>,
<a href="r.coin.html">r.coin</a>,
<a href="r.describe.html">r.describe</a>,
<a href="r.stats.quantile.html">r.stats.quantile</a>,
<a href="r.stats.zonal.html">r.stats.zonal</a>,
<a href="r.statistics.html">r.statistics</a>,
<a href="r.univar.html">r.univar</a>
</em>

<h2>AUTHORS</h2>

Michael Shapiro, U.S. Army Construction Engineering Research Laboratory<br>
Sort option by Martin Landa, Czech Technical University in Prague, 2013

<!--
<p>
<i>Last changed: $Date$</i>
-->
